<?xml version="1.0" encoding="UTF-8"?>
<!--///////////////////////////////////////////
Plantilla xsl de transforamcion del formato de metainformacion propietario del repositorio YouTube al formato universal manejado en el sistema DUMA (basado en Mpeg7)
/////////////////////////////////////////////////////-->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:yt="http://gdata.youtube.com/schemas/2007" xmlns:gd="http://schemas.google.com/g/2005" xmlns:media="http://search.yahoo.com/mrss/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:Mpeg7="urmpeg7:mpeg:mpeg7:schema:2001" xmlns:voc="vocabularies" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="fn gd media Mpeg7 atom openSearch xs xsi xsl yt" xmlns="urn:mpeg:mpeg7:schema:2001">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>
	<xsl:template match='/atom:feed'>
		<Mpeg7>
			<Description xsi:type="Mpeg7:ContentEntityType">
				<MultimediaContent xsi:type="Mpeg7:MultimediaCollectionType">
					<Collection xsi:type="Mpeg7:ContentCollectionType" name="DUMA">
						<ContentCollection name="youtube">
							<xsl:apply-templates select="atom:entry"/>				
						</ContentCollection>
					</Collection>
				</MultimediaContent>
			</Description>
		</Mpeg7>
	</xsl:template>

	<!-- Plantilla para procesar cada contenido (nodos entry en el formato de youtube)-->
	<xsl:template match="atom:entry">
		<Content xsi:type="Mpeg7:AudioVisualType"><xsl:attribute name="id"><xsl:value-of select="atom:id"/></xsl:attribute>
			<AudioVisual>
				<MediaInformation>
					<xsl:apply-templates select="media:group/media:content"/>	
				</MediaInformation>
				<CreationInformation>
					<Creation>
						<Title>
							<xsl:value-of select="media:group/media:title"/>
						</Title>
						<TitleMedia>
							<TitleImage>
								<MediaUri><xsl:value-of select="media:group/media:thumbnail[1]/@url"/></MediaUri>
							</TitleImage>
						</TitleMedia>
						<Abstract>
							<FreeTextAnnotation>
								<xsl:value-of select="media:group/media:description"/>
							</FreeTextAnnotation>
							<KeywordAnnotation>
								<Keyword><xsl:value-of select="media:group/media:keywords"/></Keyword>
							</KeywordAnnotation>
						</Abstract>
						<Creator>
							<Role href="RoleVocabulary">
								<voc:Name>Usuario YouTube</voc:Name>
							</Role>
							<Agent xsi:type="Mpeg7:OrganizationType">
								<voc:Name><xsl:value-of select="atom:author/atom:name"/></voc:Name>
								<ElectronicAddress>
									<Email><xsl:value-of select="atom:author/atom:uri"/></Email>
								</ElectronicAddress>
							</Agent>
                                                        <Instrument>
                                                            <Tool>
								<voc:Name>YouTube</voc:Name>
                                                                <voc:Definition>youtube.gif</voc:Definition>
                                                            </Tool>
							</Instrument>
						</Creator>
                                                <CreationCoordinates>
                                                    <Location></Location>
                                                    <!--Fecha en el formato dd/mm/aaaaThh:mm:ss -->
                                                    <Date><TimePoint>
                                                        <xsl:call-template name="formatDate"><xsl:with-param name="date" select="atom:published"/></xsl:call-template>
                                                    </TimePoint></Date>
                                                </CreationCoordinates>
					</Creation>
                                        
                                        <!--Clasificacion. Genero y Rating -->
                                        <Classification>
                                            <Genre href="urn:mpeg:cat">
						<voc:Name><xsl:value-of select="media:group/media:category/@label"/></voc:Name>
                                            </Genre>
                                            <MediaReview>
                                                <Rating>
                                                    <RatingValue><xsl:value-of select="gd:rating/@average"/></RatingValue>
                                                    <RatingScheme best="5.0" style="higherBetter">
                                                        <voc:Name>Rating</voc:Name>
                                                        <voc:Definition>Duma</voc:Definition>
                                                    </RatingScheme>
                                                </Rating>
                                            </MediaReview>
                                        </Classification>
				</CreationInformation>
			</AudioVisual>
		</Content>
	</xsl:template>
	
	<xsl:template match="media:content">
		<MediaProfile>
			<MediaInstance>
				<InstanceIdentifier><xsl:value-of select="@url"></xsl:value-of></InstanceIdentifier>
				<LocationDescription><xsl:value-of select="@type"></xsl:value-of></LocationDescription>
			</MediaInstance>
		</MediaProfile>
	</xsl:template>
        
        <!--Transforma el formato de fecha definido en picasaweb en el formato utilizado internamente por el sistema en Mpeg7-->
        <xsl:template name="formatDate">
            <xsl:param name="date"/>
            
            <xsl:variable name="dia" select="substring($date,9,2)"/>
            <xsl:variable name="mes" select="substring($date,6,2)"/>
            <xsl:variable name="anyo" select="substring($date,1,4)"/>
            
            <xsl:value-of select="$dia"/>/<xsl:value-of select="$mes"/>/<xsl:value-of select="$anyo"/>
            
        </xsl:template>
        
</xsl:stylesheet>
